package com.smarthealthcare.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smarthealthcare.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smarthealthcare.common.annotation.Log;
import com.smarthealthcare.common.core.controller.BaseController;
import com.smarthealthcare.common.core.domain.AjaxResult;
import com.smarthealthcare.common.enums.BusinessType;
import com.smarthealthcare.domain.Register;
import com.smarthealthcare.service.IRegisterService;
import com.smarthealthcare.common.utils.poi.ExcelUtil;
import com.smarthealthcare.common.core.page.TableDataInfo;

/**
 * 预约Controller
 *
 * @author ruoyi
 * @date 2024-11-23
 */
@RestController
@RequestMapping("/register/yuyue")
public class RegisterController extends BaseController
{
    @Autowired
    private IRegisterService registerService;

    /**
     * 查询预约列表
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:list')")
    @GetMapping("/list")
    public TableDataInfo list(Register register)
    {
        startPage();
        List<Register> list = registerService.selectRegisterList(register);
        return getDataTable(list);
    }

//    @Anonymous
    @PreAuthorize("@ss.hasPermi('register:yuyue:list')")
    @GetMapping("/getall/getAll")
    public TableDataInfo getAll()
    {
        List<Register> list = registerService.selectAll();
        return getDataTable(list);
    }

    /**
     * 导出预约列表
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:export')")
    @Log(title = "预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Register register)
    {
        List<Register> list = registerService.selectRegisterList(register);
        ExcelUtil<Register> util = new ExcelUtil<Register>(Register.class);
        util.exportExcel(response, list, "预约数据");
    }

    /**
     * 获取预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(registerService.selectRegisterById(id));
    }

    /**
     * 新增预约
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:add')")
    @Log(title = "预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Register register) {
        int result = registerService.insertRegister(register);
        if (result > 0) {
            return AjaxResult.success("操作成功", register);  // 将 register 对象返回，其中包含生成的 id
        } else {
            return AjaxResult.error("新增预约失败");
        }
    }


    /**
     * 修改预约
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:edit')")
    @Log(title = "预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Register register)
    {
        return toAjax(registerService.updateRegister(register));
    }

    /**
     * 删除预约
     */
    @PreAuthorize("@ss.hasPermi('register:yuyue:remove')")
    @Log(title = "预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(registerService.deleteRegisterByIds(ids));
    }
}
